﻿using JHECIS.DataModel;
using JHWpfToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace JHECIS.BLL.Triage.Common
{
    public class NotifiactionHelper
    {
        /// <summary>
        /// 通用换回结果转提示信息实体 2022-03-18 袁凤超
        /// </summary>
        /// <param name="commonResult"></param>
        /// <returns></returns>
        public static NotifiactionModel TransNotifiactionModel(CommonResult commonResult)
        {
            NotifiactionModel res = new NotifiactionModel();
            if (commonResult != null)
            {
                if (commonResult.Result)
                {
                    res.Title = "操作成功";
                    res.NotifiactionType = EnumPromptType.Success;
                }
                else
                {
                    res.Title = "操作失败";
                    res.NotifiactionType = EnumPromptType.Warn;
                }
                res.Content = commonResult.ErrMsg;
            }
            else
            {
                res.Title = "操作失败";
                res.Content = "数据异常！";
                res.NotifiactionType = EnumPromptType.Error;
            }
            return res;
        }

        private static readonly Lazy<NotifiactionHelper> _lazy = new Lazy<NotifiactionHelper>(() => new NotifiactionHelper(), LazyThreadSafetyMode.PublicationOnly);

        readonly Notifiaction notifiaction = Notifiaction.Instance;

        /// <summary>
        /// 单例对象 袁凤超 2023-06-20
        /// </summary>
        public static NotifiactionHelper Instance
        {
            get
            {
                return _lazy.Value;
            }
        }

        /// <summary>
        /// 消息提示 袁凤超 2023-06-20
        /// </summary>
        /// <param name="content"></param>
        /// <param name="title"></param>
        /// <param name="proType"></param>
        public void ShowMessage(string title, string content, EnumPromptType proType)
        {
            notifiaction.Dispatcher.BeginInvoke(new Action(() =>
            {
                notifiaction.AddNotifiaction(new NotifiactionModel()
                {
                    Title = title,
                    Content = content,
                    NotifiactionType = proType
                });
            }));
        }
    }
}
